package com.ae.shield.common.jei;

import com.ae.shield.common.config.Config;
import com.ae.shield.common.items.ItemList;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.conditions.TagEmptyCondition;

import java.util.ArrayList;

public class JEIHider {
    private final ArrayList<ItemStack> hiddenItems = new ArrayList<>();

    public void hide() {
//        addItem(ItemList.RENDER_ITEM.get());
        if (!Config.METAL_PROCESSING.get()) {
            addItems(ItemList.PLATES_ENDERIUM.get(), ItemList.PLATES_GOLD.get(), ItemList.PLATES_IRON.get(), ItemList.PLATES_LEAD.get());
            addItems(ItemList.DUSTS_ALUMINUM.get(), ItemList.DUSTS_ENDERIUM.get(), ItemList.DUSTS_GOLD.get(), ItemList.DUSTS_IRON.get(), ItemList.DUSTS_SILVER.get());
            addItems(ItemList.HAMMER.get());
        }

        if (!Config.ORE_GENERATE.get()) {
            addItems(ItemList.ORES_ALUMINUM.get(), ItemList.ORES_LEAD.get(), ItemList.ORES_MANGANESE.get(), ItemList.ORES_SILVER.get(), ItemList.ORES_TANTALUM.get(), ItemList.ORES_TIN.get());
        }
    }

    public void addItems(Item... items) {
        for (Item item : items) {
            hiddenItems.add(new ItemStack(item));
        }
    }

    public void addItem(Item item) {
        hiddenItems.add(new ItemStack(item));
    }

    public void addConditionItems(ICondition condition, boolean reverse, Item... items) {
        if (reverse) {
            if (!condition.test()) {
                addItems(items);
            }
        } else {
            if (condition.test()) {
                addItems(items);
            }
        }
    }

    public void addConditionItem(ICondition condition, boolean reverse, Item item) {
        if (reverse) {
            if (!condition.test()) {
                addItem(item);
            }
        } else {
            if (condition.test()) {
                addItem(item);
            }
        }
    }

    public void addTagEmptyItem(Item item, boolean reverse, String tagID) {
        addConditionItem(new TagEmptyCondition(tagID), reverse, item);
    }

    public static ArrayList<ItemStack> getList() {
        JEIHider jeiHider = new JEIHider();
        jeiHider.hide();
        return jeiHider.hiddenItems;
    }
}
